Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arbitrary role resource version in the editor #51160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bl-nero
Copy link
Contributor

@bl-nero bl-nero commented Jan 17, 2025

This PR allows changing role resource through the standard editor. It also introduces version-specific validation to the Kubernetes resource access definitions.

Since updateRoleModel function became a bit more involved, I also switched the reducer to use Immer to make it easier to manipulate the domain objects.

Screenshot 2025-01-17 at 12 56 18
Screenshot 2025-01-17 at 12 56 33

@bl-nero bl-nero added the no-changelog Indicates that a PR does not require a changelog entry label Jan 17, 2025
@bl-nero bl-nero force-pushed the bl-nero/role-editor-versions branch from e5ba20a to 4d3e7c2 Compare January 17, 2025 11:58
Copy link
Contributor

@avatus avatus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great tests!

options={roleVersionOptions}
value={value.version}
onChange={version => onChange({ ...value, version })}
// rule={precomputed(validation.fields.verbs)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

@@ -351,6 +355,7 @@ function KubernetesResourceView({
}) {
const { kind, name, namespace, verbs } = value;
const theme = useTheme();
console.log('ROLE VERSION', value.roleVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove console

@@ -83,6 +83,7 @@
"d3-time-format": "^4.1.0",
"date-fns": "^2.28.0",
"history": "^4.9.0",
"immer": "^10.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR description, can you also explain a bit more on why we chose "immer" over other alternatives please?

That information will be valuable for anyone looking for origin of immer as dependency.

<LabelsInput
disableBtns={isProcessing}
labels={value.labels}
setLabels={labels => onChange?.({ ...value, labels })}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onChange is optional? Why?

options={roleVersionOptions}
value={value.version}
onChange={version => onChange({ ...value, version })}
// rule={precomputed(validation.fields.verbs)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// rule={precomputed(validation.fields.verbs)}

dead code

@@ -159,6 +161,24 @@ test('edits resource access', async () => {
expect(role.spec.allow.logins).toEqual(['{{internal.logins}}', 'ec2-user']);
});

test('propagates version info to Kubernetes resource access', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename this test to "triggers v6 validation for kubernetes resource."

I initially got confused otherwise since the test only says propagates version info but we are interested in validation triggered at the end.

await selectEvent.select(screen.getByLabelText('Kind'), 'Job');
await user.click(screen.getByRole('button', { name: 'Create Role' }));

// Validation should have failed on a Job resource and role v6.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assert that some validation error message appears on the screen?

Comment on lines +382 to +386
export type RoleVersionOption = Option<RoleVersion>;
export const roleVersionOptions: RoleVersionOption[] = (
['v7', 'v6', 'v5', 'v4', 'v3'] as const
).map(stringToOption);
export const roleVersionOptionsMap = optionsToMap(roleVersionOptions);
Copy link
Contributor

@flyinghermit flyinghermit Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just generally curious here - why we picked as const and not something like enums?

verbs: ValidationResult;
};

const validKubernetesKind = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: JSDoc

};

export type RoleVersion = 'v3' | 'v4' | 'v5' | 'v6' | 'v7';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define role versions once and reuse them? These are also defined in the standardmodal.ts file

@bl-nero
Copy link
Contributor Author

bl-nero commented Jan 17, 2025

Note to self: there's a bug that prevents adding more than one resource. I need to fix it before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v17 no-changelog Indicates that a PR does not require a changelog entry size/md ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants